import { _decorator, Animation, Component, ICollisionEvent, instantiate, Node, Prefab, Sprite, Vec3 } from 'cc';
import PlantImpl from './PlantImpl';
const { ccclass, property } = _decorator;

@ccclass('PlantsController')
export class PlantsController extends Component implements PlantImpl{
    price: number;
    @property(Node)
    rootNode: Node = null;
    @property(Prefab)
    bullet: Prefab = null;
    @property(Animation)
    animation: Animation = null;
    @property(Number)
    attackSpeed: number = 3;
    isPlanted: boolean = false;
    start() {
        this.node.on('plant',()=>{
            this.onPlanted()
        })
    }
    onPlanted(){
        this.animation.play()
    }
    onHit(){
        this.schedule(this.addBullet,this.attackSpeed)
    }

    addBullet(){
        //复制预制体
        let bullet = instantiate(this.bullet);
        bullet.setPosition(10,0,0)
        this.rootNode.addChild(bullet);
    }
    update(deltaTime: number) {
        
    }
}

